import { fetchWrapper } from './common';

export type ContryObj = {
	latitude: string;
	lineType: '1' | '2';
	longitude: string;
	name: string;
	quantity: number;
};

/**
 * 海运航线坐标
 */
export type CoordinatesNodes = {
	latitude: string;
	longitude: string;
}
// 海运
export type SeawayRoutes = {
	lineType: 1 | 2; //1 是标准的航线（原来的那种） 2. 是优势航线
	podCn: string; // 目的港中文名
	podCode: string; // 目的港code
	podEn: string; // 目的港英文名
	polCn: string; // 起运港中文名
	polCode: string; // 起运港code
	polEn: string; // 起运港英文名
	quantity: number; // 数量
	coordinatesNodes: CoordinatesNodes[]; // 航线坐标
}

// 两仓一线
export type WarehoseRoutes = {
	podName: string; // 目的港中文名
	polName: string; // 起运港中文名
	coordinateData: CoordinatesNodes[]; // 航线坐标
}

export type GlobeDataType = {
  currentMonthOrderCount: number;
  earthObj: {
    countryObjList: ContryObj[];
    coordinatesVoList: SeawayRoutes[];
    latitude: string;
    longitude: string;
  };
	coordinate: WarehoseRoutes[];
};

const mockData =
  typeof window !== 'undefined' &&
	(new URL(window.location.href).searchParams.get('mockData')) || '';
  
export const getGlobeDataApi = () => {
	return fetchWrapper<GlobeDataType>(
    `/big-screen/api/v2/businessIndicator/preview?mockData=${mockData}`
  );
};

export type StatisticsDataType = {
	oceanLastThrityDayTeu: number; // 海运近30天订单量
	yearGrowthRate: number; // 2024 同比增速
	airliftMonthPcs: string; // 空运月年度出运量
	dedicatedLineOrderYearNum: number; // 集拼累计订单数
	dedicatedLineOrderMonthVal: number; // 集拼累计出运量
	airliftYearOrderCount: string; // 空运年度订单数
	airliftYearPcs: string; // 空运年度出运量
	airliftYearWeight: number; // 空运年度出运总重量
	dedicatedLineOrderYearVal: number; // 散货年度出运量
	customerCount: string; // 客户总数
	newCustomerCount: string; // 本月新增客户数
	oceanMonthTeu: number; // 海运月年度出运量
	oceanYearTeu: number; // 海运年度出运量
	oceanYdbYearTeu: number;
	lastYearOceanYearTeu: number; // 上年海运年度出运量
	oceanYearCarrierCount: number; // 海运年度出运航司
	oceanYearCountryCount: number; // 海运年度国家
	oceanYearDischargePortCount: number; // 海运年度目的港
	oceanYearLineCount: number; // 海运年度涉及航线
	oceanYearReceiveCount: number; // 海运年度接单数
	oceanYearShipmentCount: number; // 海运年度出运数
	shipmentCount: number; // 本月出运客户数
	storageArea: null; // 仓储面积
	storageOrderCount: string; // 仓储订单数
	supplierCount: string; // 供应商数
	trailerOrderCount: string; // 拖车订单数
	weatherInfo: string; // 天气信息
	overseasStorageArea: string;
};

export const getStatisticsDataApi = () => {
	return fetchWrapper<StatisticsDataType>(
		`/big-screen/screen/businessIndicator/globalSupply/refreshStatistics?mockData=${mockData}`
	);
};

export type OrderCount = {
	airliftQuantity: number;
	oceanQuantity: number;
	totalQuantity: number;
	// 集拼
	dedicatedLineOrderMonthVal: number;
	//海运近30天订单量
	oceanLastThrityDayTeu: number;
};
export const getOrderCountApi = () => {
	return fetchWrapper<OrderCount>(
		`/big-screen/screen/businessIndicator/queryOrderCount?mockData=${mockData}`
	);
};

export type OrderItem = {
	dischargePortCode: string;
	dischargePortName: string;
	loadPortCode: string;
	loadPortName: string;
	orderNo: string;
	shipEtd: number;
};
export const getCDOCOrderApi = () => {
	return fetchWrapper<OrderItem[]>(
		`/big-screen/screen/businessIndicator/queryCdocOrderList?mockData=${mockData}`
	);
};
export type MonthSeawayData = {
	monthList: string[];
	xyObjList: {
		x: string;
		y: string;
		z: string;
	}[];
};
export const getSeawayApi = () => {
	return fetchWrapper<MonthSeawayData>(
		`/big-screen/screen/businessIndicator/queryOrderTrendChart?mockData=${mockData}`
	);
};

